<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="./js/request.js"></script>
  <link rel="stylesheet" href="./css/style.css">
  <title>主页</title>
</head>

<body>
  <h1>这是主页</h1>
  <a href="./post.html">
    <h2>去分页！</h2>
  </a>
  <script>
    // 请求源地址
    const url = 'http://localhost:8000/data?'

    // 请求数据
    const data = {
      user: 'admin',
      password: 123456
    }

    console.log('HELLO 我是客户端, 向服务器发送 GET 请求：')
    console.log('验证信息为：')
    console.log(data)

    const req = new Request()
    req.request('GET', url, data)
      .then(res => {

        if (res.err) {
          console.log('服务器发来消息：')
          console.log(res.err)
          return
        }

        console.log('已收到服务器返回的数据！非常感谢！')

        if (res.datas) {
          res.datas = String.prototype.split.call(res.datas, ',').map(item => item * 1)
        }

        console.log(res)
      })
      .catch(err => console.log(err))
  </script>
</body>

</html>